home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / GAM / 0-B / Billiards.cpt / Billiard Parlour Info.TEXT < prev    next >
Text File  |  1987-11-11  |  13KB  |  262 lines

  1. Billiard Parlour
  2. General Operation
  3. Each game has a CUE BALL, except Billiards has two.  A cue ball may be
  4. launched with the mouse.  This is done by placing the mouse near the ball,
  5. pressing, then dragging out a cue line.  The ball is launched upon release
  6. of the mouse button, with speed proportional to the dragged length of the
  7. cue line and direction determined by the line.  No ball other than cue 
  8. ball(s) may be shot; for Billiards the launched ball is always the one 
  9. closest to the initial press-down point of the mouse.
  10.  
  11. Be careful not to shoot too hard - if you 'slam' a nearby object ball, you
  12. may get a 'hop' and not hit the object solidly.  A little practice will
  13. reveal this.  
  14.  
  15. You can arrange balls by holding down the Option key of the keyboard while
  16. you press on, and subsequently drag, a ball.  A menu item 'Arrange Balls'
  17. also performs this function, but must be deselected after arrangement is
  18. complete.  
  19. >>
  20. A hand-cursor results whenever balls may be arranged.  Sunk 
  21. balls deposited near the bottom of the screen can be moved back onto the 
  22. table without recourse to the Option key or menu.
  23.  
  24. ENGLISH is invoked by selecting same on the Options menu, upon which a 
  25. picture of the cue ball face appears to the right of the table. The white 
  26. spot shows where the next shot will strike the cue ball.  Note two things: 
  27. the spot reverts to the default position after each shot, and this default 
  28. lies at the theoretical zero-english height of 7/5 radius.
  29.  
  30. The collision sounds may be turned on or off via the Options menu item
  31. 'Sound'.  Likewise, 'English' has the effect of hiding or bringing
  32. back the English display.  This menu item does not affect the value of
  33. English, which in any case always reverts to zero after any shot.
  34. >>
  35. Scoring may be performed with the 100-carrom scoring rack atop the screen.  
  36. When using the carroms, simply drag carroms to and fro.  The TURN SCORE is always reported in the central display just below the carrom rack.  This 
  37. is the number of balls sunk on the previous turn.  For straightforward 
  38. turns the number will be the amount to add into the current player's 
  39. cumulative score.  For scratches, etc. one has to carefully apply whatever 
  40. scoring rules have been agreed upon; in such cases the central display is 
  41. intended as a guide, not an actual score.
  42.  
  43. SCRATCHES are reported (as beeps) when the cue ball is sunk, or in
  44. 8-ball when the 8 is sunk.  For cue ball scratches, the ball is placed
  45. in the right-hand half of the table, at an open location.  As usual the
  46. cue ball may be moved with the Option key or the Options menu entry
  47. 'Arrange Balls'.
  48. >>
  49.  
  50. The Games
  51.  
  52. In BILLIARDS the players alternate between the spotted and unspotted cue
  53. balls.  A score is logged on the central display when the current cue ball
  54. strikes the other two object balls, but only if three rails are hit
  55. by the cue ball before the second object ball is struck.
  56.  
  57. In STRAIGHT POOL the rack is numbered consecutively from 1 through 15, and sunk balls will be deposited in numerical order.
  58.  
  59. In 8-BALL the rack has a central 8 ball, with a certain pattern of solids
  60. and stripes surrounding, and sunk balls are deposited with solids to the
  61. left and stripes to the right.  There are many different 'favorite' 8-Ball 
  62. rack configurations:  the one chosen for this program guarantees a fairly 
  63. even distribution of stripe/solid placement over a number of breaks. 
  64. >>
  65. In 9-BALL the rack has a central 9 ball, with a certain pattern of balls 1
  66. through 8 surrounding.  Sunk balls are deposited in numerical order.
  67.  
  68. In SNOOKER there are fifteen unmarked balls in the rack, with numbered 
  69. balls 2,3,4,5,6,7 in specific places.  Sunk balls are deposited in two 
  70. groups: numbered and unmarked.
  71.  
  72. In SLOP there are optional rack sizes, and all object balls are unmarked. 
  73.  
  74. The LAG game simply automates the 'lagging' process in which players 
  75. alternately launch a cue ball to see who can come closer to a point or 
  76. rail.  As with other options, players may choose their own lag criteria, 
  77. with the program providing decision aid - in this case a lag line is drawn 
  78. on the screen to indicate final cue ball position.  The lag also has the 
  79. feature that the cue ball may be either dragged or shot while the item is 
  80. checked.  NOTE: This item must be deselected to enable any other game.
  81. >>
  82.  
  83.  
  84. The Racks
  85.  
  86. The menu items 'Complete Rack' and 'Continuation Rack' provide means for
  87. setting up games.  'Complete Rack' is used to start afresh.  'Continuation
  88. Rack' makes the most sense in Straight Pool variations, by racking all but
  89. the final ball left on the table.  If the number of object balls left is 
  90. less than or greater than one, or if the single ball left is within the 
  91. 15-ball racking triangle the Complete Rack results as a default.
  92. >>
  93. Magnification
  94.  
  95. This is to aid in reading ball numbers and assessing complex positions.
  96.  
  97.   Glass:  A rectangle will follow the mouse movements.  Hold down the
  98.           mouse button to magnify the selected area.  An <Option>-Click
  99.           or a Double-click will cause the magnifying glass to disappear.
  100.   FullScreen:  The table is blown up to greater than full-screen size.  
  101.           Drag the mouse, with the button held down, to scroll the 
  102.           full screen display (as in MacPaint 'ShowPage' mode). An 
  103.           <Option>-Click or a Double-click will cause the screen
  104.           to revert to normal.
  105.  
  106.  
  107. Note:  The startup display (with animated Billiard Parlour scene) may be
  108.        speeded up by holding down the <Option> key.
  109. ~~
  110.  
  111. Origins of Billiard Parlour
  112.  
  113. The project was started as a sharp test of Rascal animation.  We had
  114. worked out fast 'integer calculus' routines for colliding bodies and
  115. performing various rapid graphics functions. These formulas and techniques
  116. coupled with bit-copying of ball images formed the basis for
  117. the reasonably realistic billiard effects.  The final application was thus
  118. written entirely within the Rascal compiler/development system 
  119. environment.
  120.  
  121. The following technical remarks may be of interest to the serious 
  122. programmer.
  123. >>
  124. Perhaps the most salient fact about the billiards algorithms is that no
  125. floating point is used whatsoever.  All calculations are done in 16-bit
  126. integer format.  The reason, of course, is the quest for speed.  Though
  127. floating point variables are easier to work with for dynamical problems,
  128. there is no hope for full pool table dynamics on the Macintosh unless
  129. integer calculations predominate.
  130. >>
  131. The speed of the integer dynamical routines should be evident from a
  132. consideration of what must be done to iterate an entire ensemble of hard
  133. spheres.  Say there are N spheres total in motion on the table.  One must
  134. on every pass of the main iteration loop
  135.  
  136.      1) Update 2N coordinate values.
  137.      2) Update 2N velocity values.
  138.      3) Seek and analyze collisions, requiring N*N/2 checks.
  139.      4) Handle damping and English.
  140.      5) For most games, check for pocket sinking for each of the N balls.
  141.      6) Check for rail bounces for each of N balls.
  142.      
  143. Naturally, some of the above are interrelated - for example collision and
  144. damping are what imply the need for updating velocities.  The fact that
  145. N*N/2 checks are used to seek all collisions is especially cumbersome when
  146. the number N in the ensemble is large.  For a full pool table, this means
  147. 128 checks for collisions are made at each iteration.
  148. >>
  149. An example of trickery intended to optimize speed is that used to check 
  150. for collisions.  The Rascal source has a collision algorithm essentially 
  151. like so:
  152.  
  153.      s := 4*radius*radius;
  154.      loop(,i:=0,++i,i>numballs-1)
  155.      {
  156.        loop(i<numballs-1, j:=i+1, ++j, j>numballs-1)
  157.        {
  158.            dx := x[i] - x[j];
  159.            if dx*dx <= s then
  160.               { dy:= y[i] - y[j];
  161.                 if dx*dx + dy*dy <= s then
  162.                    collide(i,j);
  163.               };
  164.        };
  165.      };
  166.  
  167.  
  168. The two loops are straightforward, dictating that we are checking for
  169. pair (i,j) collisions where i is not equal to j.  But the primary point is 
  170. that the check dx*dx<s is made first to save time.  Note that two balls 
  171. have collided (that is, penetrate each other) whenever
  172.  
  173.     sqrt(dx*dx + dy*dy) <= 2*radius
  174.     
  175. so collision also implies sqrt(dx*dx)< 2*radius.  The 'sqrt' function can
  176. be dropped, as in the explicit loop above, in the interest of speed.
  177.  
  178. Many such integer calculations were necessary to achieve a certain 
  179. realism.  
  180. >>
  181. Other examples which might interest the programmer are:
  182.  
  183.      1) Each ball has two pictures, which alternate after every multiple
  184.         of pi*radius is moved on the screen.  This gives an impression of
  185.         rolling.
  186.      2) Damping is hard to accomplish with integers.  The primary problem
  187.         is that if we attempt at each iteration something like:        
  188.               vx[i]:= (vx[i]*999)/1000;
  189.               vy[i]:= (vy[i]*999)/1000;              
  190.         then, in general, one of vx or vy will vanish completely before 
  191.         the other, at the tail end of a ball's motion.  This causes 
  192.         swerving at the end of the trajectory, as a ball disappointingly 
  193.         follows one axis or the other.  The solution was to apply the 
  194.         formula only at certain times - not in each iteration - and make 
  195.         sure that total damping is achieved before the final swerve.  This 
  196.         last effect is done by simply stopping the motion after a certain 
  197.         iteration count which depends in turn on the game played and on 
  198.         other conditions.
  199. >>
  200.      3) The difficulty with integer calculus is evident when one considers
  201.         the basic Newtonian iteration:
  202.         
  203.              x[i]:= x[i] + vx[i];
  204.              y[i]:= y[i] + vy[i];
  205.              
  206.         noting that in real-number calculus one would have each velocity
  207.         term multiplied by a small time increment dt.  Because we cannot
  208.         do this with integers (the smallest increment being 1) there is
  209.         the threat that balls will move very far at each iteration.  The
  210.         solution is easy enough: hold all coordinates and velocities as 
  211.         large integers, and divide by a constant only when actually 
  212.         graphing.  Thus in Billiard Parlour the typical coordinates are on 
  213.         the order of 10000 and divisions by 100 are typical at graph time.
  214. >>
  215.      4) The problem of English is a good example of a tough-sounding 
  216.      problem which turns out to be rather trivial to solve.  For English 
  217.      effects at a rail, we add to the reflected velocity the following 
  218.      cross- product expression:
  219.         
  220.               k(omega X velocity)
  221.               
  222.      where omega is a unit vector normal to the plane of the table and 
  223.      indicating angular rotation, while k is the value of (horizontal)
  224.      English.  For vertical English at a rail, we simply add to the normal 
  225.      reflected component Vn the quantity h*Vn where h is now the vertical 
  226.      English.  These rules are not completely exact physically, but it is 
  227.      easy to show that the major qualitative behavior of English at rails 
  228.      is handled correctly with these simple calculations.  For English 
  229.      during ball-ball encounters, the same formula are used, but relegated 
  230.      of course to the center-of-momentum frame, where each ball sees in 
  231.      effect the other ball as a 'rail'.
  232. >>
  233.      5) Billiard Parlour dynamical calculations are not exact, and for the
  234.         sake of speed some 'molecular' effects - in which balls stick 
  235.         together momentarily - have been left in.  These effects occur 
  236.         primarily because of the ambiguity between incoming and outgoing 
  237.         collisions: if two balls mutually penetrate, it is not easy to 
  238.         find out whether they have just had their velocities reflected, or 
  239.         whether now is the time to so reflect.  The ambiguity is 
  240.         especially fierce when many balls are banging around in a clutch.  
  241.         So the application was designed for speed: there is a molecule 
  242.         from time to time, but the molecule does not stay together.  
  243.         Removing all unrealistic effects proves to take too much compute 
  244.         time away from the otherwise pleasing motion.
  245. >>
  246. The serious programmer may also be interested in the various utilities and
  247. methods unrelated to dynamics that went into the project.  The 
  248. magnification feature for reading balls and positions easily is a good 
  249. example of Rascal off-screen port graphics.  The sound of ball clicks is 
  250. achieved by free-form synthesis of 'chirp' waves - i.e. high-frequency, 
  251. brief tone bursts.  The graphics problem presented by the carroms scoring 
  252. rack is surprisingly difficult, and stands as a good example of straight 
  253. quickdraw methods.
  254.  
  255. The key graphics procedures are found on the standard Rascal Jan 1986
  256. release as library entries.  The key library is called __GraphUtils, and
  257. has many things from screen initialization to high-speed sine, cosine, and
  258. square root functions; in general integer techniques for fast graphics.
  259. But other libraries are involved heavily - the interested programmer can
  260. consult the Billiard Parlour source listing in conjunction with the Rascal
  261. User Manual.
  262.